/**
 * The class is used to contain and sort the citations of a publication.
 * 
 */
public class CitationsForYear implements Comparable<CitationsForYear>{

	private int nCite;
	private int year;
	/**
	 * Construct a CitationsForYear object.
	 * 
	 * @param nYear the year of citation.	
 	 * @param aNCite the amount of citation.
	 */
	CitationsForYear(int nYear, int aNCite) {
		this.year = nYear;
		this.nCite = aNCite;
	}
	/**
	 * Return the amount of citations.
	 * 
	 * @return citations.
	 */
	public int getnCite() {
		return nCite;
	}
	/**
	 * Set the amount of citations.
	 * 
	 * @param nCite number of citations.
	 */
	public void setnCite(int nCite) {
		this.nCite = nCite;
	}
	/**
	 * Return the year of citation.
	 * 
	 * @return the year.
	 */
	public int getYear() {
		return year;
	}
	/**
	 * Set the year of citation.
	 * 
	 * @param year the year.
	 */
	public void setYear(int year) {
		this.year = year;
	}
	@Override
	/**
     * Returns the String representation of the object.
	 * 
	 * @return the string representation.
     */	
	public String toString() {
		return this.year + " " + this.nCite;
	}

	@Override
	/**
	 * Returns a hash code for this object.
	 * 
	 * @return a hash code value for this object.
	 */
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + nCite;
		result = prime * result + year;
		return result;
	}

	@Override
	/**
	 * Compares this to the specified object obj. 
	 * The result is true if and only if the argument is not null and is a 
	 * CitationForYear object that have the same year and citations.
	 * 
	 * @param obj the object to compare this against.
	 * @return true if the given object represents a CitationForYear equivalent to this, false otherwise.
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CitationsForYear other = (CitationsForYear) obj;
		if (nCite != other.nCite)
			return false;
		if (year != other.year)
			return false;
		return true;
	}
	@Override
	/**
	 * Compares two CitationForYear objects. The comparison is based on the override of equals.
	 * 
	 * @param temp an CitationsForYear object to compare.
	 * @return the value 0 if the argument is equal to this; a value less than 0 if this is less than the argument; 
	 * 		   and a value greater than 0 if this is greater than the argument.
	 */
	public int compareTo(CitationsForYear temp) {
		Integer year1 = new Integer(this.year);
		Integer year2 = new Integer(temp.year);
		int tmp = year1.compareTo(year2) ;
		if (tmp != 0)
			return tmp;

		else{
			Integer cit1 = new Integer(this.nCite);
			Integer cit2 = new Integer(temp.nCite);
			int tmp1 = cit1.compareTo(cit2);
			return tmp1;
		}
	}

}
